package com.example.shoppingmall.cotroller;

import com.example.shoppingmall.Utils.Page;
import com.example.shoppingmall.config.MyLog;
import com.example.shoppingmall.pojo.Invoice;
import com.example.shoppingmall.service.InvoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/invoice")
public class InvoiceController {
    @Autowired
    InvoiceService invoiceService;

    //排序+分页遍历+条件查询
    @RequestMapping("invoicelist")
    public String invoicelist(@RequestParam(value = "cno",required = false) String cno,@RequestParam(value = "ono",required = false) String ono,
                              @RequestParam(value = "dtime",required = false) String dtime,
                              @RequestParam(value = "InvoiceNo",required = false) String InvoiceNo, @RequestParam(value = "orderno",required = false) String orderno,
                              @RequestParam(value = "CourierNo",required = false) String CourierNo, @RequestParam(value = "phone",required = false) String phone,
                              @RequestParam(value = "pageno",defaultValue = "1") String pageno, @RequestParam(value = "pageSize",defaultValue = "6") String pageSize,
                              Model model, HttpSession session){
        session.setAttribute("InvoiceNo",InvoiceNo);
        session.setAttribute("orderno",orderno);
        session.setAttribute("CourierNo",CourierNo);
        session.setAttribute("phone",phone);
        int count=invoiceService.Invoicecount(InvoiceNo, orderno, CourierNo, phone);
        int num=(Integer.valueOf(pageno)-1)*Integer.valueOf(pageSize);
        Page page=new Page();
        page.setPageno(Integer.valueOf(pageno));
        page.setPageCount(count);
        page.setPageSize(Integer.valueOf(pageSize));
        List<Invoice> invoiceList=invoiceService.getAllinvoicelist(cno,ono,dtime,InvoiceNo,orderno,CourierNo,phone,num,Integer.valueOf(pageSize));
        model.addAttribute("page",page);
        model.addAttribute("invoiceList",invoiceList);
        return "order/Invoice";
    }

    //查询详情
    @MyLog(value = "订单管理->发货单->查看明细")
    @RequestMapping("/selinvoice")
    public String selinvoice(int id,Model model){
        Invoice invoice=invoiceService.getlistById(id);
        model.addAttribute("invoice",invoice);
        return "order/InvoiceSelected";
    }
}
